package com.example.Service.Impl;

import com.example.Mapper.Stu_CourMapper;
import com.example.Mapper.StudentMapper;
import com.example.Pojo.PageQuery;
import com.example.Pojo.Result;
import com.example.Pojo.Student;
import com.example.Service.StudentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private Stu_CourMapper stuCourMapper;
    @Override
    public PageQuery<Student> list(Integer page,Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<Student> studentPage=studentMapper.list();
        Page<Student> page1=(Page<Student>) studentPage;
        return new PageQuery<Student>((int) page1.getTotal(),page1.getResult());
    }

    @Override
    public void addStudent(Student student) {
        studentMapper.addStudent(student);
    }

    @Override
    public void deleteStudent(Integer id) {
        studentMapper.deleteByStuId(id);
        stuCourMapper.deleteByStuId(id);
    }

    @Override
    public void updateStudent(Student student) {
        studentMapper.updateStudent(student);
        //学号不允许修改
    }
}
